{extend name="layout/base"}

{block name="content"}
<form class="layui-form">
    <div class="layui-container">
        <input type="hidden" name="uid" value="{$uid}">
        <div class="layui-form-item">
            <label class="layui-form-label">旧密码</label>
            <div class="layui-input-block">
                <input type="password" class="layui-input" name="oldPwd" placeholder="请输入旧密码" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input type="password" class="layui-input" name="newPwd" placeholder="请输新密码" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-block">
                    <input type="password" class="layui-input" name="newPwd1" placeholder="请再次输入新密码" lay-verify="required">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="submit">提交</button>
            </div>
        </div>
    </div>
</form>

<script>
    layui.use(['jquery', 'form', 'layer'], function ($, form, layer) {

        form.on('submit(submit)', function (obj) {
            var index = parent.layer.getFrameIndex(window.name)
            $.ajax({
                type: 'post',
                data: obj.field,
                url: "{:url('user/editPwd')}",
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg,{icon:6});
                        // parent.layer.close(index);
                        parent.layer.iframeAuto(index);
                        top.location.reload();
                    } else {
                        layer.msg(data.msg,{icon:5});
                    }
                },
                error: function () {
                    layer.msg('请求错误',{icon:5});
                }
            });

            return false;
        });
    });
</script>
{/block}